package evocarcassonne.core.specs.board;

import evocarcassonne.core.board.Board;
import evocarcassonne.core.board.Tile;
import evocarcassonne.core.board.locations.Position;
import evocarcassonne.core.utils.ZoneType;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
public class BoardFixture {

    Board board = new Board();

    public void createTile(String north, String east, String south, String west, String x, String y, String rotation) throws Exception {

        Tile tile = new Tile();

        switch (north) {
            case "CITY":
                tile.setNorth(ZoneType.CITY);
                break;
            case "ROAD":
                tile.setNorth(ZoneType.ROAD);
                break;
            case "MEADOW":
                tile.setNorth(ZoneType.MEADOW);
                break;
            default:
                throw new Exception("Not a Valid north ZoneType : " + north);
        }

        switch (east) {
            case "CITY":
                tile.setEast(ZoneType.CITY);
                break;
            case "ROAD":
                tile.setEast(ZoneType.ROAD);
                break;
            case "MEADOW":
                tile.setEast(ZoneType.MEADOW);
                break;
            default:
                throw new Exception("Not a Valid east ZoneType : " + east);
        }

        switch (south) {
            case "CITY":
                tile.setSouth(ZoneType.CITY);
                break;
            case "ROAD":
                tile.setSouth(ZoneType.ROAD);
                break;
            case "MEADOW":
                tile.setSouth(ZoneType.MEADOW);
                break;
            default:
                throw new Exception("Not a Valid south ZoneType : " + south);
        }

        switch (west) {
            case "CITY":
                tile.setWest(ZoneType.CITY);
                break;
            case "ROAD":
                tile.setWest(ZoneType.ROAD);
                break;
            case "MEADOW":
                tile.setWest(ZoneType.MEADOW);
                break;
            default:
                throw new Exception("Not a Valid west ZoneType : " + west);
        }

        switch (rotation) {
            case "0":
                tile.rotate0();
                break;
            case "90":
                tile.rotate90();
                break;
            case "180":
                tile.rotate180();
                break;
            case "270":
                tile.rotate270();
                break;
            default:
                throw new Exception("Not a Valid rotation : " + rotation);
        }


        tile.setPosition(new Position(Integer.parseInt(x), Integer.parseInt(y)));

        if (board.CanPlaceTile(tile, tile.getPosition())) {
            board.placeTile(tile.getPosition(), tile);
        } else {
            throw new Exception("Board can't place " + tile + " at this position : " + tile.getPosition());
        }
    }

    public int holesNumber() {

        return board.getHoles().size();
    }
    
    public boolean searchHole(String stringHole) {

        for (Position hole : board.getHoles()) {
            if (hole.toString().equals(stringHole)) {
                return true;
            }
        }
        return false;
    }
}
